/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package noodlesscm;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class ProductSelected
{
    JFrame jfps=new JFrame("Enter the Product ID");
    JButton jbps=new JButton("OK");
    JPanel jpps=new JPanel();
    JLabel jl1=new JLabel("Enter the Product ID :");
    JLabel jl2=new JLabel("Enter Quantity");
    JTextField tfproid;
    JTextField tfproq;
    FileReader frs1;
    BufferedReader br1;
    String s,productId,productName,reqInvList;
    String[] cline,ri ;
    String[] reqInv;

    void gettingProduct()
    {   
        jfps.setLayout(new BorderLayout());
        tfproid=new JTextField();
        tfproid.setColumns(20);
        tfproq=new JTextField();
        tfproq.setColumns(20);

        jfps.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        
        jpps.setSize(35,35);
        jpps.add(jl1);
        jpps.add(tfproid);
        jpps.add(jl2);
        jpps.add(tfproq);
        jpps.add(jbps);

        jbps.addActionListener(new getProductselected());

//      jfps.add(tfproid,BorderLayout.NORTH);
//      jfps.add(jbps,BorderLayout.SOUTH);
        jfps.setSize(300,200);
        jfps.add(jpps,BorderLayout.CENTER);
        jfps.setVisible(true);
    }

        class getProductselected implements ActionListener{

        public void actionPerformed(ActionEvent event)
        {
            try {
                currentInventory1();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ProductSelected.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            }

        }

        private void currentInventory1() throws FileNotFoundException {
        try {
            int reqproductid;
            int reqproductqua;
            ArrayList<Product> p = new ArrayList<Product>();
            p.add(new Product());
            p.add(new Product());
            p.add(new Product());
            p.add(new Product());
            p.add(new Product());
            p.add(new Product());
            p.add(new Product());
            p.add(new Product());
            reqproductid = Integer.parseInt(tfproid.getText());
            reqproductqua = Integer.parseInt(tfproq.getText());
            
            frs1 = new FileReader("GUIProduct.txt");
            br1 = new BufferedReader(frs1);
            int i = 0;
            while ((s = br1.readLine()) != null)
            {
                cline = s.split(",");
                p.get(i).setName(cline[0]);
                p.get(i).setProductid(Integer.parseInt(cline[1]));
                p.get(i).setQuantity(Integer.parseInt(cline[2]));
                p.get(i).setDescription(cline[3]);
                p.get(i).setInvenlist(cline[4]);
                System.out.println(p.get(i).getName());
                i++;

                for(int k=0;k<i;k++)
                    {
                        while(p.get(k).getProductid() == reqproductid)
                        {
//                            reqInvList=p.get(k).getInvenlist();
//                            reqInv=reqInvList.split(";");
//                            for(int j=0;j<reqInv.length;j++)
//                            {
//                                System.out.print(reqInv[j]);
//                            }
                            System.out.println("got it"+k);
                        }
                    }
            }
        } catch (IOException ex) {
            Logger.getLogger(ProductSelected.class.getName()).log(Level.SEVERE, null, ex);
        }

        }
        

    }

//        public void currentInventory() throws FileNotFoundException, IOException
//        {
//            int reqproductid;
//            int reqproductqua;
//            int id,i=0;
//            
//            String s,productId,productName,reqInvList;
//            String[] cline,ri ;
//            String[] reqInv;
//
//            reqproductid=Integer.parseInt(tfproid.getText());
//            reqproductqua=Integer.parseInt(tfproq.getText());
//
//            frs=new FileReader("GUIProduct.txt");
//            br=new BufferedReader(frs);
//            while((s=br.readLine()) != null)
//		{
//		cline=s.split(",");
//                p.get(i).setName(cline[0]);
//                p.get(i).setProductid(Integer.parseInt(cline[1]));
//                p.get(i).setQuantity(Integer.parseInt(cline[2]));
//                p.get(i).setDescription(cline[3]);
//                p.get(i).setInvenlist(cline[4]);
//                i++;
//                }
////                for(int k=0;k<i;k++)
////                    {
////                        while(p.get(k).getProductid() == reqproductid)
////                        {
////                            reqInvList=p.get(k).getInvenlist();
////                            reqInv=reqInvList.split(";");
////                            for(int j=0;j<reqInv.length;j++)
////                            {
////                                System.out.print(reqInv[j]);
////                            }
////                        }
////                    }
////                rm=rmrq.split(";");
////                if(x==s1)
////                    {
////                       j=rm.length;
////                       for(int k=0;k<j;k++)
////                                {
////                                      a[k]=rm[k];

           }
}
        
                
        
